﻿using Mes.Domain.BoundedContext.EntityBase;

namespace Mes.Domain.BoundedContext.Entities.Quality
{
    /// <summary>
    /// 质量规格特性关联表
    /// </summary>
    public class QmSpecCharLink : NoIdEntityBase
    {
        public QmSpecCharLink() { }

        public QmSpecCharLink(int qmSpecId, int charId, double target, double? usv, double? lsv, DateTime lastEditAt)
        {
            Qm_Spec_Id = qmSpecId;
            Char_Id = charId;
            Target = target;
            Usv = usv;
            Lsv = lsv;
            Last_Edit_At = lastEditAt;
        }

        /// <summary>
        /// 质量规格id
        /// </summary>
        public int Qm_Spec_Id { get; set; } = 0;

        /// <summary>
        /// 特性id
        /// </summary>
        public int Char_Id { get; set; } = 0;

        /// <summary>
        /// 目标
        /// Target value for this characteristic for this QM specification context
        /// </summary>
        public double Target { get; set; } = 0;

        /// <summary>
        /// 规格下限
        /// Lower specification limit, maintained automatically from lsv, lsv_is_offset, and possibly lsv_offset_is_pct and target.
        /// </summary>
        public double? Lsv { get; set; } = null;

        /// <summary>
        /// 规格上限
        /// Upper specification limit, maintained automatically from usv, usv_is_offset, and possibly usv_offset_is_pct and target.
        /// </summary>
        public double? Usv { get; set; } = null;

        /// <summary>
        /// 规格下限为低于/高于目标的偏差
        /// Is lsv the difference between target and lsl.  i.e. lsv is not equal to lower spec limit (lsl) but is an offset. Default = No
        /// </summary>
        public bool Lsv_Is_Offset { get; set; } = false;

        /// <summary>
        /// 规格上限为低于/高于目标的偏差
        /// Is usv the difference between usl and target, i.e. usv is not equal to upper spec limit (usl) but is an offset.  Default = No
        /// </summary>
        public bool Usv_Is_Offset { get; set; } = false;

        /// <summary>
        /// 规格下限为低于/高于目标的百分比
        /// Is lsv an offset, is it a percent of the target?  Default = No
        /// </summary>
        public bool Lsv_Offset_Is_Pct { get; set; } = false;

        /// <summary>
        /// 规格上限为低于/高于目标的百分比
        /// Is usv an offset, is it a percent of the target? Default = No
        /// </summary>
	    public bool Usv_Offset_Is_Pct { get; set; } = false;

        /// <summary>
        /// Lower specification limit, maintained automatically from lsv, lsv_is_offset, and possibly lsv_offset_is_pct and target.
        /// </summary>
        public double? Lsl { get; set; } = null;

        /// <summary>
        /// Upper specification limit, maintained automatically from usv, usv_is_offset, and possibly usv_offset_is_pct and target.
        /// </summary>
        public double? Usl { get; set; } = null;

        /// <summary>
        /// Lower reasonable value
        /// </summary>
        public double? Lrv { get; set; } = null;

        /// <summary>
        /// Upper reasonable value
        /// </summary>
        public double? Urv { get; set; } = null;

        /// <summary>
        /// Is lrv a multiplier for the difference between the lower spec limits and target, to find offset from target for lrl; if not, lrv = lower reasonable limit (an absolute value)  Default = No
        /// </summary>
        public bool Lrv_Is_Mult { get; set; } = false;

        /// <summary>
        /// Is urv a multiplier for the difference between the upper spec limits and target, to find offset from target for url; if not, urv = upper reasonable limit (an absolute value)  Default = No
        /// </summary>
        public bool Urv_Is_Mult { get; set; } = false;

        /// <summary>
        /// 严重性
        /// Override char setting of severity
        /// </summary>
        public int? Severity_Cd { get; set; } = null;

        /// <summary>
        /// 采样计划id
        /// Override QM_spec choice for sample plan
        /// </summary>
	    public int? Plan_Id { get; set; } = null;

        /// <summary>
        /// 样本大小来源
        /// (([sample_size_source]>=(0) AND [sample_size_source]<=(2)))
        /// If type = 1 or 2 (attribute) 0 = fixed, 1 = entered, 2 = entered but initially copied from the previous value
        /// </summary>
        public int? Sample_Size_Source { get; set; } = null;

        /// <summary>
        /// 标准样本大小
        /// If variable or attribute with fixed sample size, the normal number of measurements in a sample
        /// </summary>
        public int? Normal_Sample_Size { get; set; } = null;

        /// <summary>
        /// 最小样本大小
        /// </summary>
        public int? Minimum_Sample_Size { get; set; } = null;

        /// <summary>
        /// 最大样本大小
        /// </summary>
        public int? Maximum_Sample_Size { get; set; } = null;

        /// <summary>
        /// 控制极限来源
        /// [cl_source]>=(0) AND [cl_source]<=(3)
        /// 0 = automatically calculate from data (default), 1 = compute from standard mean and standard deviation values (if variable) or compute from standard p, np average proportion and standard c, u average number per unit values (if attribute), 2 = use preset values
        /// </summary>
        public int? Cl_Source { get; set; } = null;

        /// <summary>
        /// 控制极限的样本
        /// If cl_source = 0, the maximum number of samples to use for the calculation of control limits.
        /// </summary>
        public int? Samples_For_Cl { get; set; } = null;

        /// <summary>
        /// 计算控制限制之前所必需的样本
        /// If cl_source = 0, the number of samples required before control limits are calculated.
        /// </summary>
        public int? Samples_Before_Cl { get; set; } = null;

        /// <summary>
        /// 标准平均值
        /// Only meaningful if cl_source = 1 (may not then be null).  If type is variable this is the standard mean; if a binary attribute this is the standard p, np average proportion value; if a counted attribute this is the standard c, u average number per unit value.
        /// </summary>
        public double? Std_Avg { get; set; } = null;

        /// <summary>
        /// 标准平均值为目标
        /// Only meaningful if cl_source = 1.  If not null, used to override the std_avg_is_target setting for the characteristic; allowable values are 0 and 1. If 1 use the target instead of the std_avg value as the standard.
        /// </summary>
        public int? Std_Avg_Is_Target { get; set; } = null;

        /// <summary>
        /// 标准偏差
        /// If variable and cl_source = 1, the standard deviation
        /// </summary>
        public double? Std_Deviation { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 1, the standard deviation
        /// </summary>
        public double? Cl_Xbar { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, lower control limit for x_bar
        /// </summary>
        public double? Lcl_Xbar { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, upper control limit for x_bar
        /// </summary>
        public double? Ucl_Xbar { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, center line for range
        /// </summary>
        public double? Cl_Range { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, lower control limit for range
        /// </summary>
        public double? Lcl_Range { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, upper control limit for range
        /// </summary>
        public double? Ucl_Range { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, center line for sigma
        /// </summary>
        public double? Cl_Sigma { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, lower control limit for sigma
        /// </summary>
        public double? Lcl_Sigma { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, upper control limit for sigma
        /// </summary>
        public double? Ucl_Sigma { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, center line for individual x
        /// </summary>
        public double? Cl_Ix { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, lower control limit for individual x
        /// </summary>
        public double? Lcl_Ix { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, upper control limit for individual x
        /// </summary>
        public double? Ucl_Ix { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, center line for individual moving range
        /// </summary>
        public double? Cl_Imr { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, lower control limit for individual moving range
        /// </summary>
        public double? Lcl_Imr { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, upper control limit for individual moving range
        /// </summary>
        public double? Ucl_Imr { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, center line for moving average
        /// </summary>
        public double? Cl_Ma { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, lower control limit for moving average
        /// </summary>
        public double? Lcl_Ma { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, upper control limit for moving average
        /// </summary>
        public double? Ucl_Ma { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, center line for moving range
        /// </summary>
        public double? Cl_Mr { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, lower control limit for moving range
        /// </summary>
        public double? Lcl_Mr { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, upper control limit for moving range
        /// </summary>
        public double? Ucl_Mr { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, center line for moving sigma
        /// </summary>
        public double? Cl_Ms { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, lower control limit for moving sigma
        /// </summary>
        public double? Lcl_Ms { get; set; } = null;

        /// <summary>
        /// If variable and cl_source = 2, upper control limit for moving sigma
        /// </summary>
        public double? Ucl_Ms { get; set; } = null;

        /// <summary>
        /// If attribute and cl_source = 2, center line for p
        /// </summary>
        public double? Cl_P { get; set; } = null;

        /// <summary>
        /// If attribute and cl_source = 2, lower control limit for p
        /// </summary>
        public double? Lcl_P { get; set; } = null;

        /// <summary>
        /// If attribute and cl_source = 2, upper control limit for p
        /// </summary>
        public double? Ucl_P { get; set; } = null;

        /// <summary>
        /// If attribute and cl_source = 2, center line for np
        /// </summary>
        public double? Cl_Np { get; set; } = null;

        /// <summary>
        /// If attribute and cl_source = 2, lower control limit for np
        /// </summary>
        public double? Lcl_Np { get; set; } = null;

        /// <summary>
        /// If attribute and cl_source = 2, upper control limit for np
        /// </summary>
        public double? Ucl_Np { get; set; } = null;

        /// <summary>
        /// If attribute and cl_source = 2, center line for c
        /// </summary>
        public double? Cl_C { get; set; } = null;

        /// <summary>
        /// If attribute and cl_source = 2, lower control limit for c
        /// </summary>
        public double? Lcl_C { get; set; } = null;

        /// <summary>
        /// If attribute and cl_source = 2, upper control limit for c
        /// </summary>
        public double? Ucl_C { get; set; } = null;

        /// <summary>
        /// If attribute and cl_source = 2, center line for u
        /// </summary>
        public double? Cl_U { get; set; } = null;

        /// <summary>
        /// If attribute and cl_source = 2, lower control limit for u
        /// </summary>
        public double? Lcl_U { get; set; } = null;

        /// <summary>
        /// If attribute and cl_source = 2, upper control limit for u
        /// </summary>
        public double? Ucl_U { get; set; } = null;

        /// <summary>
        /// 默认图
        /// (([default_chart]=(20) OR [default_chart]=(19) OR [default_chart]=(18) OR [default_chart]=(17) OR [default_chart]=(16) OR [default_chart]=(8) OR [default_chart]=(7) OR [default_chart]=(5) OR [default_chart]=(3) OR [default_chart]=(2)))
        /// If not null, override value in char table; 2 = XBar + Range, 3 = XBar + Sigma, 5 = IX + MR, 7 = MA + Range, 8 = MA + Sigma, 16 = p, 17 = np, 18 = u, 19 = c, 20 = DPMO (coding per QI Analyst)
        /// </summary>
        public int? Default_Chart { get; set; } = null;

        /// <summary>
        /// 自动收集
        /// [automated_coll]>=(0) AND [automated_coll]<=(2)
        /// Is this characteristic to be collected automatically? 0 = No, 1 = Yes, 2 = Use characteristic setting (default)
        /// </summary>
        public int Automated_Coll { get; set; } = 2;

        /// <summary>
        /// 收集时间间隔
        /// If sample size > 1 and automated_coll is Yes, the interval between samples.  Note this is a default for the characteristic, which can be overridden independently at each SRO
        /// </summary>
        public int? Time_Interval { get; set; } = null;

        /// <summary>
        /// 时间间隔单位
        /// (([time_int_unit]>=(0) AND [time_int_unit]<=(2)))
        /// 0 = seconds, 1 = minutes, 2 = hours
        /// </summary>
        public int? Time_Int_Unit { get; set; } = null;

        /// <summary>
        /// Order in which to display characteristics within a specification
        /// (([display_seq] IS NOT NULL AND [display_seq]>=(1)))
        /// </summary>
        public int Display_Seq { get; set; } = 1;

        /// <summary>
        /// 最新更新备注，为何更新
        /// </summary>
	    public string? Last_Edit_Comment { get; set; } = null;

        /// <summary>
        /// 最新更新用户
        /// </summary>
        public string Last_Edit_By { get; set; } = string.Empty;

        /// <summary>
        /// 最新更新时间
        /// </summary>
        public DateTime Last_Edit_At { get; set; } = DateTime.Now;

        /// <summary>
        /// 行数，从0开始按1自增
        /// </summary>
        public int Row_Id { get; set; } = 0;
    }
}
